home *** CD-ROM | disk | FTP | other *** search
- package sun.tools.zip;
-
- import java.io.IOException;
- import java.io.InputStream;
-
- class ZipFileInputStream extends InputStream implements ZipConstants {
- private ZipFile zipFile;
- private ZipEntry zipEntry;
- private long pos;
- private long count;
-
- public ZipFileInputStream(ZipFile var1, ZipEntry var2) throws ZipFormatException, IOException {
- this.zipFile = var1;
- this.zipEntry = var2;
- this.init();
- }
-
- public synchronized int read(byte[] var1, int var2, int var3) throws ZipFormatException, IOException {
- if (this.count == 0L) {
- return -1;
- } else {
- if ((long)var3 > this.count) {
- var3 = (int)this.count;
- }
-
- int var4 = this.zipFile.read(this.pos, var1, var2, var3);
- if (var4 == -1) {
- throw new ZipFormatException("Invalid LOC header");
- } else {
- this.pos += (long)var4;
- this.count -= (long)var4;
- return var4;
- }
- }
- }
-
- public synchronized int read() throws ZipFormatException, IOException {
- if (this.count == 0L) {
- return -1;
- } else {
- int var1 = this.zipFile.read();
- if (var1 == -1) {
- throw new ZipFormatException("Invalid LOC header");
- } else {
- ++this.pos;
- --this.count;
- return var1;
- }
- }
- }
-
- public synchronized long skip(long var1) {
- if (var1 > this.count) {
- var1 = this.count;
- }
-
- this.pos += var1;
- this.count -= var1;
- return var1;
- }
-
- private void init() throws ZipFormatException, IOException {
- byte[] var1 = new byte[30];
- this.zipFile.read(this.zipEntry.locpos, var1, 0, 30);
- byte[] var2 = ZipConstants.LOCSIG;
- if (!ZipFile.checkSig(var1, 0, var2)) {
- throw new ZipFormatException("Invalid LOC header signature");
- } else if ((var1[8] & 255 | (var1[9] & 255) << 8) != 0) {
- throw new ZipFormatException("Compressed entries not supported");
- } else if (((var1[6] & 255 | (var1[7] & 255) << 8) & 1) == 1) {
- throw new ZipFormatException("Encrypted entries not supported");
- } else {
- this.count = this.zipEntry.length;
- this.pos = this.zipEntry.locpos + 30L + (long)(var1[26] & 255 | (var1[27] & 255) << 8) + (long)(var1[28] & 255 | (var1[29] & 255) << 8);
- if (this.pos + this.count > this.zipFile.cenpos) {
- throw new ZipFormatException("Invalid LOC header format");
- }
- }
- }
- }
-